﻿<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="com.zaofan.bean.Lable"%>
<%@page import="com.zaofan.cache.CacheManage"%>
<%@page import="com.zaofan.constant.LableConstant"%>
<%@page import="com.zaofan.bean.Carrier"%>
<%@page import="com.zaofan.service.CarrierAreaService"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
	String contextPath = request.getContextPath();
	Carrier carrier = (Carrier)session.getAttribute("carrier");
	if(carrier == null){
		response.sendRedirect(contextPath + "/loginCarrier.jsp?state=" + "session-invalid");
		return;
	}
	CarrierAreaService carrierAreaService = new CarrierAreaService();
	String areaIds = carrierAreaService.findByCarrierIdAreaToIds(carrier.getId());
	if(areaIds == null ||"".equals(areaIds)){
		areaIds = "-1";
	}
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>今日下单订单</title>
<link href="<%=contextPath%>/admin/css/base.css" rel="stylesheet" />
<link href="<%=contextPath%>/admin/assets/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/font-awesome.min.css" />
<!--[if IE 7]>
	<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/font-awesome-ie7.min.css" />
<![endif]-->
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace.min.css" />
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-rtl.min.css" />
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-skins.min.css" />
<!--[if lte IE 8]>
	<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-ie.min.css" />
<![endif]-->
<script src="<%=contextPath%>/admin/assets/js/ace-extra.min.js"></script>
<!--[if lt IE 9]>
	<script src="<%=contextPath%>/admin/assets/js/html5shiv.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/jquery-ui-1.10.3.custom.min.css" />
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/chosen.css" />
<script type="text/javascript">  
       var contextPath='<%=contextPath%>';
       var areaIds='<%=areaIds%>';
</script>
</head>
<body style="background-color: #fff;">
						<%
								application.setAttribute("special", CacheManage.specialShop);
								application.setAttribute("expressType", CacheManage.lables.get(LableConstant.lable_express_type));
							%>
	<div class="page-content">
		<div class="row" style="height: 100%">
			<div class="col-xs-12">
				<div class="panel panel-default">
				  <div class="panel-heading">订单打印</div>
				  <div class="panel-body">
				  </div>
				</div>
			
				<div class="panel panel-default">
				  <div class="panel-heading">订单查找</div>
				  <div class="panel-body">
				  		<form class="form-inline">
								<input type="hidden" value="" id="property"  />
								<input type="hidden" value="" id="key"  />
								<input type="hidden" value="" id="accountMobile"  />
								<label for="key">号码：</label>
								<input id="mobile" class="form-control" value="" style="width:100px;" />&nbsp;&nbsp;
								<button type="button" class="btn btn-primary btn-sm" id="find">查找</button>
						</form>
				  </div>
				</div>
			</div>
			<div class="col-xs-12">
			<style>
				.table-responsive table th tr{text-align: center;}
			</style>
				<div class="table-responsive">
					
					<input type="hidden" value="1" id="start" />
					<table id="sample-table-2"
						class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th style="text-align: center;">订单号</th>
								<th style="text-align: center;">用户</th>
								<th style="text-align: center;">下单时间</th>
								<th style="text-align: center;">送餐时间</th>
								<th style="text-align: center;">价格</th>
								<th style="text-align: center;">收货信息</th>
								<th style="text-align: center;">状态</th>
								<th style="text-align: center;">支付状态</th>
								<th style="text-align: center;">操作</th>
							</tr>
						</thead>
						<tbody id="data-list"  style="text-align: center;">
						</tbody>
					</table>
				</div>
			</div>
			<!-- /.col -->
		</div>
		<!-- /.row -->
		<div class="row">
			<div class="col-sm-6">
				<div id="sample-table-2_info" class="dataTables_info">
					当前    <span id="current">  </span> 到  <span id="page"></span> 总共 <span
						id="total"></span> 条
				</div>
			</div>
			<div class="col-sm-6">
				<div class="dataTables_paginate paging_bootstrap">
					<ul class="pagination pagination-sm" id="page-list">
					</ul>
				</div>
			</div>
		</div>
	</div>
	<style>
		#detailsBox{border:1px solid #999;border-bottom:none;}
		#detailsBox thead tr th{width:20%;padding:10px;}
		#detailsBox thead tr{border-bottom:1px solid #999;}
		#detail-list tr{border-bottom:1px solid #999;}
		
	</style>
	<div id="detailsBox" style="width: 900px;position: absolute;display:none; ">
		<table id="sample-table-2"
			class=""  style="background-color:#f5f5f5;width:100%">
			<thead  style="background-color:#f5f5f5;width:100%">
				<tr>
					<th style="text-align: center;">产品名</th>
					<th style="text-align: center;">产品图片</th>
					<th style="text-align: center;">产品价格</th>
					<th style="text-align: center;">产品数量</th>
					<th style="text-align: center;">商铺信息</th>
				</tr>
			</thead>
			<tbody id="detail-list" style="text-align: center;background-color:#f5f5f5">
			</tbody>
		</table>
	</div>
	
	<div id="loading"
		style="width: 32px; height: 32px; position: fixed; left: 40%; top: 40%; display: none;">
		<img src="<%=contextPath%>/admin/assets/css/images/loading.gif"
			width="32" height="32" />
	</div>
	
	<div class="popover"
		style="z-index: 9999; width: 150px; position: fixed; left: 40%; top: 40%;">
		<div class="arrow"></div>
		<div class="popover-inner">
			<h3 class="popover-title">操作提示</h3>
			<div class="popover-content" id="popover-content">
				<p>操作成功</p>
			</div>
		</div>
	</div>
	
	
	<script type="text/javascript">
		if ("ontouchend" in document)
			document
					.write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
							+ "<"+"/script>");
	</script>
	<script type="text/javascript">
		window.jQuery
				|| document
						.write("<script src='<%=contextPath%>/admin/assets/js/jquery-2.0.3.min.js'>"
								+ "<"+"script>");
	</script>
	
	<!--[if IE]>
		<script type="text/javascript">
			window.jQuery || document.write("<script src='<%=contextPath%>/admin/assets/js/jquery-1.10.2.min.js'>"+"<"+"script>");
		</script>
	<![endif]-->
	<script type="text/javascript">
		if ("ontouchend" in document)
			document
					.write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
							+ "<"+"script>");
	</script>
	<script src="<%=contextPath%>/admin/assets/js/bootstrap.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/typeahead-bs2.min.js"></script>

	<!--[if lte IE 8]>
		  <script src="assets/js/excanvas.min.js"></script>
	<![endif]-->
	<script src="<%=contextPath%>/admin/assets/js/jquery-ui-1.10.3.custom.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.ui.touch-punch.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.slimscroll.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.easy-pie-chart.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.sparkline.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/ace-elements.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/ace.min.js"></script>
	<script src="<%=contextPath%>/admin/js/common.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery-form.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/date-time/bootstrap-datepicker.min.js"></script>
	
	
	<script type="text/javascript">
	var time = null;
	
	
	
		function getOrder(val){
			getData(1);
		}
	
		$(function(){
				init();
		});
		function init() {
			getData(1);
		}

		function getData(start) {
			var property = "";
			if($("#accountMobile").val() != ""){
				if(property == ""){
					property = "accountMobile=" + $("#accountMobile").val();
				}else{
					property += "&accountMobile=" + $("#accountMobile").val();
				}
			}
			$("#loading").show();
				$.ajax({
					url : contextPath + '/order' + (property == "" ? "" : "?" + property),
					type : "POST",
					dataType : 'json',
					data : {
						action : 'today_list',
						areaId : "in"+areaIds,
						begin : (start - 1) * 20,
						end : 20,
						order:' by orderTime desc'
					},
					success : function(rs, textStatus, jqXHR) {
						if (rs.success) {
							var data = rs.data;
							var total = rs.total;
							var dataList = $("#data-list");
							dataList.empty();
							$("#total").text(total);
							$("#current").text((start - 1) * 20 + 1);
							if (data.length > 0) {
								$("#page").text(
										(start - 1) * 20 + data.length);
								parseData(data, total, start);
							} else {
								showMessage("无数据");
							}
						} else {
							showMessage("获取数据失败,请稍后再试");
						}
						$("#loading").hide();

					},
					error : function() {
						$("#loading").hide();
						showMessage("请稍后再试");
					}
			});
		}

		function parseData(data, total, start) {
			var dataList = $("#data-list");
			var tr = "";
			for (var i = 0; i < data.length; i++) {
				tr += '<tr>';
				tr += '<td><a href="javascript:void(0)"  class="showDetai" orderId='+data[i].id+' detailInfo="">'+data[i].orderNo+'</a></td>';
				tr += '<td>'+data[i].accountMobile+'</td>';
				tr += '<td>'+data[i].orderTime+'</td>';
				tr += '<td>'+data[i].sendDate + '<br/>'+data[i].sendTime+'</td>';
				tr += '<td>总价:'+data[i].totalPrice+'<br/>支付价格:'+data[i].payPrice+'<br/>优惠价格:'+data[i].freePrice+'</td>';
				tr += '<td>收货人:'+data[i].consignee+'<br/>大楼:'+data[i].builderName+'<br/>楼层:'+data[i].floorNo+'<br/>电话：'+data[i].userMobile+'</td>';
				if(data[i].state == 0){
					tr += '<td>未付款</td>';
				}else if(data[i].state == 1){
					tr += '<td>已付款</td>';
				}else if(data[i].state == 2){
					tr += '<td>已评论</td>';
				}
				
				if(data[i].payState == 0){
					tr += '<td>未付款</td>';
				}else if(data[i].payState == 1){
					tr += '<td>支付确认</td>';
				}else if(data[i].payState == 2){
					tr += '<td>支付</td>';
				}else if(data[i].payState == 3){
					tr += '<td>归档</td>';
				}
				tr += '<td><input type="hidden" value="'+data[i].id+'" class="rankId"/><a target="_blank" href="'+contextPath + '/order?action=print_order&orderId=' + data[i].id +'" >打印</a></td>';
				tr += '</tr>';
			}
			dataList.append(tr);
			
			$(".showDetai").hover(function(event){
				clearTimeout(time); 
				var pointX = event.pageX;
				//这里可以得到鼠标Y坐标
				var pointY = event.pageY;
				console.log("x = " + pointX + ",y = " + pointY);
				$("#detailsBox").css("top",(pointY+20)+"px");
				$("#detailsBox").css("left",(pointX+20)+"px");
				var box = $(this);
				var id = $(this).attr("orderId");
				var detailInfo = $(this).attr("detailInfo");
				if(detailInfo != ""){
					$("#detail-list").empty();
					$("#detail-list").append(detailInfo);
					$("#detailsBox").show();
					return;
				}
				$("#loading").show();
				$.ajax({
					url : contextPath + '/order',
					type : "POST",
					dataType : 'json',
					data : {
						action : 'detail',
						id:id
					},
					success : function(rs, textStatus, jqXHR) {
						if (rs.success) {
							var data = rs.data;
							var tr = "";
							for(var i = 0 ; i < data.length ; i++){
								tr += '<tr>';
								tr += '<td>'+data[i].productName+'</a></td>';
								tr += '<td><img src="' + contextPath + data[i].productImage+'" width="40px" height="40" /></td>';
								tr += '<td>'+data[i].productPrice+'</td>';
								tr += '<td>'+data[i].productCount+'</td>';
								tr += '<td>'+data[i].shopName+'</td>';
								tr += '</tr>';
							}
							box.attr("detailInfo",tr)
							$("#detail-list").empty();
							$("#detail-list").append(tr);
							$("#detailsBox").show();
						} else {
							showMessage("获取数据失败,请稍后再试");
						}
						$("#loading").hide();
					},
					error : function() {
						$("#loading").hide();
						showMessage("请稍后再试");
					}
				});
				
			},function(){
				time = setTimeout( function(){
					$("#detailsBox").hide();
				} , 1000); 
			});
			
			//分页
			var pageList = $("#page-list");
			pageList.empty();
			pageList.append(getPageInfo20(start, total));
			$("html,body").animate({scrollTop:0},200);	
		}
		
		$("#detailsBox").hover(function(){
			clearTimeout(time); 
		},function(){
			clearTimeout(time); 
			$("#detailsBox").hide();
		});
		$("#find").click(function(){
			$("#accountMobile").val($("#mobile").val());
			getData(1);
			
		});
	</script>
</body>
</html>